﻿@{
    ViewBag.Title = "RoleList";
    Layout = "~/Views/Shared/_Main.cshtml";
}
<script type="text/javascript">
    function ButtonSearch() {
        var n = $("#txtName").val(); 
        $("#DataGrid").datagrid({
            url: "/CodeMapping/GetList/?name=" + encodeURI(n) + "&dbName=" + encodeURI($.getUrlParam("dbName"))
            , pageNumber: 1
        });
    }
    function AddItem() {
        window.location.href = "/CodeMapping/Edit?dbName=" + encodeURI($.getUrlParam("dbName"));
    }
    function Edit(v) {
        window.location.href = "/CodeMapping/Edit/?id=" + v + "&dbName=" + encodeURI($.getUrlParam("dbName"));
    }
    function DeleteItem(v) {
        if (confirm("确定要删除吗？")) {
            $.post("/CodeMapping/Delete/?id=" + v + "&dbName=" + encodeURI($.getUrlParam("dbName")), function (res) {
                switch (res) { 
                    case "1":
                        alert("操作成功！");
                        $("#DataGrid").datagrid('reload');
                        break;
                    case "2":
                        alert("映射关系已被使用，不可删除！");
                        break;
                    default:
                        alert(res);
                        break;
                }
            });
        }
    } 
    $(function () {
        $("#DataGrid").datagrid({
            width: 800,
            height: 480,
            autoRowHeight: false,
            fitColumns: true,
            pagination: true,
            rownumbers: true,
            striped: true,
            pageList: [10, 15, 20, 25, 30],
            pageSize: 15,
            title: '映射列表',
            iconCls: 'icon-save',
            url: "/CodeMapping/GetList?dbName=" + encodeURI($.getUrlParam("dbName")),
            columns: [[
                { field: 'Name', title: '名称', width: 150 },
                { field: 'DotNetCode', title: 'DotNet编码', width: 100 },
                { field: 'DBCode', title: '数据库编码', width: 100 },
                { field: 'OrderNo', title: '排序', width: 40, align: 'center' },
                { field: 'Description', title: '描述', width: 300 }, 
                { field: 'Guid', title: '操作', width: 80, align: 'center', formatter: function (value, rowData, rowIndex) {
                    var str = "<a onclick='Edit(\"" + value + "\");' class='grid_a'>修改</a> | <a onclick='DeleteItem(\"" + value + "\");'  class='grid_a'>删除</a>";
                    return str;
                } 
            }
            ]],
            toolbar: [{
                id: 'btnadd',
                text: '新增',
                iconCls: 'icon-add',
                handler: function () {
                    AddItem();
                }
            }]
        });
    }); 
</script>
<div style="margin: 5px;">
    <div class="easyui-panel" style="width: 800px;" data-options="title:'映射列表搜索',iconCls:'icon-search'">
        <table>
            <tr>
                <td> 
                    名称：
                    <input id="txtName" type="text" class="inputSearch" style="width: 200px;" /> 
                    <input id="buttonSearch" type="button" value=" 搜索 " onclick="ButtonSearch()" />
                </td>
            </tr>
        </table>
    </div>
</div>
<div style="margin-left: 5px;">
    <table id="DataGrid">
    </table>
</div>
